package com.hurui.xiaoming.activity.me;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.activity.BaseActivity;
import com.hurui.xiaoming.adapter.ViewPagerAdapter;
import com.hurui.xiaoming.bean.Li_IsUserFinish_Result;
import com.hurui.xiaoming.fragment.me.JobInfoFragment;
import com.hurui.xiaoming.fragment.me.StudentInfoFragment;
import com.hurui.xiaoming.myconfig.PamaryKeys;

import java.util.ArrayList;
import java.util.List;

public class MyStudentAndJobActivity extends BaseActivity {

    private TabLayout tablayout ;
    private ViewPager viewPager ;
    private TextView top_title_tv;
    private List<Fragment> fragmentlists ;
    private List<String> titlelists ;
    private ViewPagerAdapter adapter ;
    private ImageView back_iv ;
    private Li_IsUserFinish_Result.DataBean data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        data = ((Li_IsUserFinish_Result.DataBean) getIntent().getSerializableExtra(PamaryKeys.UI_INFO));
        setContentView(R.layout.activity_my_student_and_job);
        data = ((Li_IsUserFinish_Result.DataBean) getIntent().getSerializableExtra(PamaryKeys.UI_INFO));
        initView();
        initTabs();
        initAction();
    }

    @Override
    public void initView() {
        tablayout = (TabLayout) findViewById(R.id.tablayout);
        back_iv = (ImageView) findViewById(R.id.back_iv);
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        top_title_tv = (TextView) findViewById(R.id.top_title_tv);

        top_title_tv.setText("身份信息");
    }

    //初始化tab
    private void initTabs() {
        fragmentlists = new ArrayList<>();

        titlelists    = new ArrayList<>() ;

        titlelists.add("学生族");
        titlelists.add("上班族");

        fragmentlists.add(StudentInfoFragment.newInstance(data));
        fragmentlists.add(JobInfoFragment.newInstance(data));

        adapter = new ViewPagerAdapter(getSupportFragmentManager()
                , this , fragmentlists , titlelists);

        tablayout.setTabMode(TabLayout.MODE_FIXED);

        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout));

        tablayout.setupWithViewPager(viewPager);
        for (int i = 0; i < tablayout.getTabCount(); i++) {
            tablayout.getTabAt(i).setText(titlelists.get(i));
        }
        if("2".equals(data.getUi_yhtype())){
            viewPager.setCurrentItem(1);
        }
       // Log.i("状态",data.getUi_yhtype());
    }

    @Override
    public void initAction() {
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onFinish();
            }
        });
    }
}
